package ru.neoflex.datatable.renders;

import java.awt.Component;

import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class ComboboxRenderer implements TableCellRenderer {
	private final ComboBoxModel model;
	
	private JComboBox comboBox;
	
	public ComboboxRenderer(ComboBoxModel model) {
		this.model = model;
		this.comboBox = new JComboBox(model);
		this.comboBox.setEditable(false);		
	}
	
	@Override
	public Component getTableCellRendererComponent(JTable table,
			Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {		
		model.setSelectedItem(value);		
		return comboBox;
	}

}
